<?php


abstract class BaseSociete extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $nom;


	
	protected $adresse;


	
	protected $cp;


	
	protected $ville;


	
	protected $pays;


	
	protected $activite;


	
	protected $email;


	
	protected $tel;


	
	protected $site_internet;

	
	protected $collStages;

	
	protected $lastStageCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getNom()
	{

		return $this->nom;
	}

	
	public function getAdresse()
	{

		return $this->adresse;
	}

	
	public function getCp()
	{

		return $this->cp;
	}

	
	public function getVille()
	{

		return $this->ville;
	}

	
	public function getPays()
	{

		return $this->pays;
	}

	
	public function getActivite()
	{

		return $this->activite;
	}

	
	public function getEmail()
	{

		return $this->email;
	}

	
	public function getTel()
	{

		return $this->tel;
	}

	
	public function getSiteInternet()
	{

		return $this->site_internet;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = SocietePeer::ID;
		}

	} 
	
	public function setNom($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->nom !== $v) {
			$this->nom = $v;
			$this->modifiedColumns[] = SocietePeer::NOM;
		}

	} 
	
	public function setAdresse($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->adresse !== $v) {
			$this->adresse = $v;
			$this->modifiedColumns[] = SocietePeer::ADRESSE;
		}

	} 
	
	public function setCp($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cp !== $v) {
			$this->cp = $v;
			$this->modifiedColumns[] = SocietePeer::CP;
		}

	} 
	
	public function setVille($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->ville !== $v) {
			$this->ville = $v;
			$this->modifiedColumns[] = SocietePeer::VILLE;
		}

	} 
	
	public function setPays($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->pays !== $v) {
			$this->pays = $v;
			$this->modifiedColumns[] = SocietePeer::PAYS;
		}

	} 
	
	public function setActivite($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->activite !== $v) {
			$this->activite = $v;
			$this->modifiedColumns[] = SocietePeer::ACTIVITE;
		}

	} 
	
	public function setEmail($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->email !== $v) {
			$this->email = $v;
			$this->modifiedColumns[] = SocietePeer::EMAIL;
		}

	} 
	
	public function setTel($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->tel !== $v) {
			$this->tel = $v;
			$this->modifiedColumns[] = SocietePeer::TEL;
		}

	} 
	
	public function setSiteInternet($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->site_internet !== $v) {
			$this->site_internet = $v;
			$this->modifiedColumns[] = SocietePeer::SITE_INTERNET;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->nom = $rs->getString($startcol + 1);

			$this->adresse = $rs->getString($startcol + 2);

			$this->cp = $rs->getString($startcol + 3);

			$this->ville = $rs->getString($startcol + 4);

			$this->pays = $rs->getString($startcol + 5);

			$this->activite = $rs->getString($startcol + 6);

			$this->email = $rs->getString($startcol + 7);

			$this->tel = $rs->getString($startcol + 8);

			$this->site_internet = $rs->getString($startcol + 9);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 10; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Societe object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(SocietePeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			SocietePeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(SocietePeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = SocietePeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += SocietePeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collStages !== null) {
				foreach($this->collStages as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = SocietePeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collStages !== null) {
					foreach($this->collStages as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = SocietePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getNom();
				break;
			case 2:
				return $this->getAdresse();
				break;
			case 3:
				return $this->getCp();
				break;
			case 4:
				return $this->getVille();
				break;
			case 5:
				return $this->getPays();
				break;
			case 6:
				return $this->getActivite();
				break;
			case 7:
				return $this->getEmail();
				break;
			case 8:
				return $this->getTel();
				break;
			case 9:
				return $this->getSiteInternet();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = SocietePeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getNom(),
			$keys[2] => $this->getAdresse(),
			$keys[3] => $this->getCp(),
			$keys[4] => $this->getVille(),
			$keys[5] => $this->getPays(),
			$keys[6] => $this->getActivite(),
			$keys[7] => $this->getEmail(),
			$keys[8] => $this->getTel(),
			$keys[9] => $this->getSiteInternet(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = SocietePeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setNom($value);
				break;
			case 2:
				$this->setAdresse($value);
				break;
			case 3:
				$this->setCp($value);
				break;
			case 4:
				$this->setVille($value);
				break;
			case 5:
				$this->setPays($value);
				break;
			case 6:
				$this->setActivite($value);
				break;
			case 7:
				$this->setEmail($value);
				break;
			case 8:
				$this->setTel($value);
				break;
			case 9:
				$this->setSiteInternet($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = SocietePeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setNom($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setAdresse($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCp($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setVille($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setPays($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setActivite($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setEmail($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setTel($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setSiteInternet($arr[$keys[9]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(SocietePeer::DATABASE_NAME);

		if ($this->isColumnModified(SocietePeer::ID)) $criteria->add(SocietePeer::ID, $this->id);
		if ($this->isColumnModified(SocietePeer::NOM)) $criteria->add(SocietePeer::NOM, $this->nom);
		if ($this->isColumnModified(SocietePeer::ADRESSE)) $criteria->add(SocietePeer::ADRESSE, $this->adresse);
		if ($this->isColumnModified(SocietePeer::CP)) $criteria->add(SocietePeer::CP, $this->cp);
		if ($this->isColumnModified(SocietePeer::VILLE)) $criteria->add(SocietePeer::VILLE, $this->ville);
		if ($this->isColumnModified(SocietePeer::PAYS)) $criteria->add(SocietePeer::PAYS, $this->pays);
		if ($this->isColumnModified(SocietePeer::ACTIVITE)) $criteria->add(SocietePeer::ACTIVITE, $this->activite);
		if ($this->isColumnModified(SocietePeer::EMAIL)) $criteria->add(SocietePeer::EMAIL, $this->email);
		if ($this->isColumnModified(SocietePeer::TEL)) $criteria->add(SocietePeer::TEL, $this->tel);
		if ($this->isColumnModified(SocietePeer::SITE_INTERNET)) $criteria->add(SocietePeer::SITE_INTERNET, $this->site_internet);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(SocietePeer::DATABASE_NAME);

		$criteria->add(SocietePeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setNom($this->nom);

		$copyObj->setAdresse($this->adresse);

		$copyObj->setCp($this->cp);

		$copyObj->setVille($this->ville);

		$copyObj->setPays($this->pays);

		$copyObj->setActivite($this->activite);

		$copyObj->setEmail($this->email);

		$copyObj->setTel($this->tel);

		$copyObj->setSiteInternet($this->site_internet);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getStages() as $relObj) {
				$copyObj->addStage($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new SocietePeer();
		}
		return self::$peer;
	}

	
	public function initStages()
	{
		if ($this->collStages === null) {
			$this->collStages = array();
		}
	}

	
	public function getStages($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseStagePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collStages === null) {
			if ($this->isNew()) {
			   $this->collStages = array();
			} else {

				$criteria->add(StagePeer::SOCIETE_ID, $this->getId());

				StagePeer::addSelectColumns($criteria);
				$this->collStages = StagePeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(StagePeer::SOCIETE_ID, $this->getId());

				StagePeer::addSelectColumns($criteria);
				if (!isset($this->lastStageCriteria) || !$this->lastStageCriteria->equals($criteria)) {
					$this->collStages = StagePeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastStageCriteria = $criteria;
		return $this->collStages;
	}

	
	public function countStages($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseStagePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(StagePeer::SOCIETE_ID, $this->getId());

		return StagePeer::doCount($criteria, $distinct, $con);
	}

	
	public function addStage(Stage $l)
	{
		$this->collStages[] = $l;
		$l->setSociete($this);
	}


	
	public function getStagesJoinEtudiant($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseStagePeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collStages === null) {
			if ($this->isNew()) {
				$this->collStages = array();
			} else {

				$criteria->add(StagePeer::SOCIETE_ID, $this->getId());

				$this->collStages = StagePeer::doSelectJoinEtudiant($criteria, $con);
			}
		} else {
									
			$criteria->add(StagePeer::SOCIETE_ID, $this->getId());

			if (!isset($this->lastStageCriteria) || !$this->lastStageCriteria->equals($criteria)) {
				$this->collStages = StagePeer::doSelectJoinEtudiant($criteria, $con);
			}
		}
		$this->lastStageCriteria = $criteria;

		return $this->collStages;
	}

} 